package com.ruoyi.web.controller.admin;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.dto.XsOrderDto;
import com.ruoyi.system.domain.vo.order.XsOrderListVo;
import com.ruoyi.system.service.IXsOrderEndService;
import com.ruoyi.system.service.IXsOrderTbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单完结表Controller
 */
@RestController
@RequestMapping("/system/order/tb")
public class XsOrderTBController extends BaseController {

    @Autowired
    private IXsOrderEndService orderSettleService;

    @Autowired
    private IXsOrderTbService orderTbService;


    /**
     * 获得统计数据
     *
     * @param orderDto
     * @return
     */
    @Log(title = "TB表统计", businessType = BusinessType.OTHER)
    @GetMapping("/getOrderStatistics")
    public AjaxResult getOrderStatistics(XsOrderDto orderDto) {
        return success(orderSettleService.getOrderStatistics(orderDto));
    }

    /**
     * 导入TB数据
     *
     * @param file
     * @return
     */
    @Log(title = "批量导入TB数据", businessType = BusinessType.IMPORT)
    @PostMapping("/importTBOrder")
    public AjaxResult importTBOrder(MultipartFile file) {
        orderTbService.importTBOrder(file);
        return success();
    }

    /**
     * 导出订单列表
     */
    @Log(title = "导出淘宝订单列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XsOrderDto orderDto) {
        List<XsOrderListVo> list = orderTbService.selectOrderList(orderDto);
        ExcelUtil<XsOrderListVo> util = new ExcelUtil<XsOrderListVo>(XsOrderListVo.class);
        util.exportExcel(response, list, "淘宝订单列表");
    }

}